<template>
	<div class="count">
		<h2>当前求和为：{{sum}}</h2>
		<h2>学校名称：{{school}}</h2>
		<h2>所学学科：{{subject}}</h2>
		<h2>授课教师：{{teacher}}</h2>
		<h2>当前求和放大10倍后：{{bigSum}}</h2>
		<h2>老师名字的大写：{{bigTeacher}}</h2>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">+</button>
		<button @click="decrement">-</button>
		<button @click="jiaOdd(n)">当前和为奇数再加</button>
		<button @click="jiaWait(n)">等一等再加</button>
		<button @click="jiaServer">问问服务器再加</button>
		<!-- <button @click="test">测试一下mapActions到底是什么？</button> -->
	</div>
</template>

<script>
	import {mapActions,mapGetters, mapState} from 'vuex'

	export default {
		name:'Count',
		data() {
			return {
				n:1,
			}
		},
		computed:{
			...mapState(['sum','school','subject','teacher']),
			...mapGetters(['bigSum','bigTeacher'])
		},
		methods: {
			// 加
			increment(){
				// this.$store.dispatch('jia',this.n)
				this.$store.commit('JIA',this.n)
			},
			//减
			decrement(){
				// this.$store.dispatch('jian',this.n)
				this.$store.commit('JIAN',this.n)
			},

			// 靠程序员自己辛辛苦苦一点点的写方法
			//#region 
			/* incrementOdd(){
				this.$store.dispatch('jiaOdd',this.n)
			},
			incrementWait(){
				this.$store.dispatch('jiaWait',this.n)
			},
			incrementServer(){
				this.$store.dispatch('jiaServer')
			}, */
			//#endregion

			// mapActions的对象写法
			// ...mapActions({incrementOdd:'jiaOdd',incrementWait:'jiaWait',incrementServer:'jiaServer'})

			// mapActions的数组写法
			...mapActions(['jiaOdd','jiaWait','jiaServer'])

			
		},
	}
</script>

<style scoped>
	.count{
		background-color: orange;
		padding: 20px;
	}
	button{
		margin-left: 10px;
	}
</style>